/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.blw.forethought.Util;

import javax.swing.JOptionPane;
import java.util.Date;

/**
 * The purpose of this class is to simplify the display and logging of messages
 * throughout the application
 *
 * @author bernard_williams
 */
public class MessageManager {

    private ConfigurationManager config = new ConfigurationManager();


    public void showInfoMsg(String text){
        JOptionPane.showMessageDialog(null,
                text,
                config.getAPP_NAME(),
                JOptionPane.INFORMATION_MESSAGE);
    }

/**
 * This method shows a dialog box for error messages
 * @param text
 */
    public void showErrMsg (String text){
        JOptionPane.showMessageDialog(null,
                text,
                config.getAPP_NAME(),
                JOptionPane.ERROR_MESSAGE);

    }

/**
 * This method shows a dialog box for general messages
 * @param text
 */
    public void logErr (String text){
                try{
            FileAccessManager fao = new FileAccessManager();
            Date date = new Date();
            fao.writeTextFile(date.toString() + " - " + text,config.getERR_LOG_FILENAME());

        }
        catch (Exception e){
            this.showErrMsg(e.toString());
        }

    }
/**
 * This method logs regular messages to the message log file
 * @param text
 */
    public void logMsg (String text){
        try{
            FileAccessManager fao = new FileAccessManager();
            Date date = new Date();
            fao.writeTextFile(date.toString() + " - " + text, config.getMSG_LOG_FILENAME());

        }
        catch (Exception e){
            this.showErrMsg(e.toString());
        }

    }
}